package com.swak.boot.config.zookeeper;

import org.springframework.boot.context.properties.ConfigurationProperties;

import com.swak.Constants;
import com.swak.utils.StringUtils;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * zookeeper 的配置
 * 
 * @author lifeng
 * @date 2020年9月15日 下午8:36:09
 */
@Getter
@Setter
@Accessors(chain = true)
@ConfigurationProperties(prefix = Constants.ZOOKEEPER_PREFIX)
public class ZookeeperProperties {

	/**
	 * 基本配置
	 */
	private String username;
	private String password;
	private String address;
	private int connectionTimeoutMs = 60 * 1000;
	private int sessionTimeoutMs = 60 * 1000;

	/**
	 * 配置中心相关的配置
	 */
	private String namespace = "public";
	private String group = "default";
	private String sharedConfigs;

	public String getAuthority() {
		if (StringUtils.isEmpty(username) && StringUtils.isEmpty(password)) {
			return null;
		}
		return (username == null ? "" : username) + ":" + (password == null ? "" : password);
	}
}
